package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.TechnicalIndexVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TechnicalIndex;
import com.ruoyi.system.service.ITechnicalIndexService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 技术指标（年k，月k，周k）Controller
 * 
 * @author ruoyi
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/system/TechnicalIndex")
public class TechnicalIndexController extends BaseController
{
    @Autowired
    private ITechnicalIndexService technicalIndexService;

    /**
     * 查询技术指标（年k，月k，周k）列表
     */
    @PreAuthorize("@ss.hasPermi('system:TechnicalIndex:list')")
    @GetMapping("/list")
    public TableDataInfo list(TechnicalIndex technicalIndex)
    {
        startPage();
        List<TechnicalIndex> list = technicalIndexService.selectTechnicalIndexList(technicalIndex);
        return getDataTable(list);
    }

    /**
     * 查询技术指标（年k，月k，周k）数据
     * 类型（年，1；月，2；周，3）
     */
    @GetMapping("/getTechnicalIndex")
    public AjaxResult getTechnicalIndex(@RequestParam String klineId,@RequestParam int type)
    {
        TechnicalIndexVo technicalIndexVo = technicalIndexService.getTechnicalIndex(Long.valueOf(klineId),type);
        return success(technicalIndexVo);
    }

    /**
     * 导出技术指标（年k，月k，周k）列表
     */
    @PreAuthorize("@ss.hasPermi('system:TechnicalIndex:export')")
    @Log(title = "技术指标（年k，月k，周k）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TechnicalIndex technicalIndex)
    {
        List<TechnicalIndex> list = technicalIndexService.selectTechnicalIndexList(technicalIndex);
        ExcelUtil<TechnicalIndex> util = new ExcelUtil<TechnicalIndex>(TechnicalIndex.class);
        util.exportExcel(response, list, "技术指标（年k，月k，周k）数据");
    }

    /**
     * 获取技术指标（年k，月k，周k）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:TechnicalIndex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(technicalIndexService.selectTechnicalIndexById(id));
    }

    /**
     * 新增技术指标（年k，月k，周k）
     */
    @PreAuthorize("@ss.hasPermi('system:TechnicalIndex:add')")
    @Log(title = "技术指标（年k，月k，周k）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TechnicalIndex technicalIndex)
    {
        return toAjax(technicalIndexService.insertTechnicalIndex(technicalIndex));
    }

    /**
     * 修改技术指标（年k，月k，周k）
     */
    @PreAuthorize("@ss.hasPermi('system:TechnicalIndex:edit')")
    @Log(title = "技术指标（年k，月k，周k）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TechnicalIndex technicalIndex)
    {
        return toAjax(technicalIndexService.updateTechnicalIndex(technicalIndex));
    }

    /**
     * 删除技术指标（年k，月k，周k）
     */
    @PreAuthorize("@ss.hasPermi('system:TechnicalIndex:remove')")
    @Log(title = "技术指标（年k，月k，周k）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(technicalIndexService.deleteTechnicalIndexByIds(ids));
    }
}
